function res = GetBasisFcn(x,knots,i,k)
    if k == 0
        if (x>=knots(i+1)) && (x<knots(i+2))
            res = 1;
        else
            res = 0;
        end
    else
        A = GetBasisFcn(x, knots, i, k-1);
        B = GetBasisFcn(x, knots, i+1, k-1);   
        if A == 0
            w1 = 0;  %防止迭代过程中 出现分母为0情况
        else
            w1 = (x - knots(i+1)) / (knots(i+k+1) - knots(i+1));
        end
        if B == 0
            w2 = 0;
        else
            w2 = (knots(i+k+2) - x) / (knots(i+k+2) - knots(i+2)); 
        end
        res = w1 * A + w2 * B;
    end
end
% function res = GetBasisFcn(x,knots,fre,k)
%     N = [];
%     for i = 1:(size(knots,2)-1)
%         if (x>=knots(i)) && (x<knots(i+1))
%             N(i,1) = 1;
%         else
%             N(i,1) = 0;
%         end
%     end
%     for i = 1:(size(knots,2)-1)
%         for j = 1:(size(knots,2)-i-1)
%             if N(j,i) == 0
%                 w1 = 0;
%             else
%                 w1 = (x-knots(j)) / (knots(i+j) - knots(j));
%             end
%             if N(j+1,i) == 0
%                 w2 = 0;
%             else
%                 w2 = (knots(i+j+1)-x) / (knots(i+j+1) - knots(j+1));
%             end
%             N(j,i+1) = w1*N(j,i) + w2*N(j+1,i);
%         end
%     end
%     
%     res = N(fre+1,k+1);
% end

